package com.mid;

/**
 * Created by Lxk on 2019/5/12.
 */

class TreeNode {

    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }
}

public class Solution222 {

    int count(TreeNode node) {
        if (node == null) {
            return 0;
        }
        int left = count(node.left);
        int right = count(node.right);
        return left + right + 1;
    }

    public int countNodes(TreeNode root) {
        return count(root);
    }

}
